/*
 * @Author: 张仁会 28396543@qq.com
 * @Date: 2022-03-24 09:33:24
 * @LastEditors: 张仁会 28396543@qq.com
 * @LastEditTime: 2022-09-11 17:56:27
 * @FilePath: \react-app\src\components\lazy_loading\index.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState, useEffect, useRef } from 'react'
import lazy_loading from './lazy_loading'

export default function Index(props) {
  let imgRef = useRef()
  let [url, setUrl] = useState('')
  let [tar, setTar] = useState(null)
  let useLazy = lazy_loading(tar)
  useEffect(() => {
    setTar(imgRef.current)
    useLazy && setUrl(props.imgurl)
  }, [useLazy])
  return (
    <img src={url} style={{ width: '100%' }} ref={imgRef} alt="" />
  )
}
